home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 25.9 KB | 909 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UScroller.cp
- // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- // MacApp
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #if qDrag
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
- #endif
-
- #ifndef __UEVENT__
- #include "UEvent.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- static VCoordinate ProportionalScroll(VCoordinate diff,
- VCoordinate scrollUnit,
- VCoordinate maxTranslationchange);
-
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // ProportionalScroll:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- VCoordinate ProportionalScroll(VCoordinate diff,
- VCoordinate scrollUnit,
- VCoordinate maxTranslationchange)
- {
- VCoordinate returnVal = 0;
- if (scrollUnit)
- returnVal = MinMax(scrollUnit, (((diff + (scrollUnit / 2)) / scrollUnit) * scrollUnit), maxTranslationchange);
-
- return returnVal;
- } // ProportionalScroll
-
-
- //========================================================================================
- // CLASS TScroller
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TScroller, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TScroller constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TScroller::TScroller()
- {
- fSBarOffsets = gZeroVRect;
- fScrollLimit = gZeroVPt;
- fMaxTranslation = gZeroVPt;
- fScrollUnit = VPoint(kStdScrollUnit, kStdScrollUnit);
- fScrollBars[hSel] = NULL;
- fScrollBars[vSel] = NULL;
- fScrollBarIdentifiers[hSel] = kNoIdentifier;
- fScrollBarIdentifiers[vSel] = kNoIdentifier;
- fConstrain[hSel] = FALSE;
- fConstrain[vSel] = FALSE;
- fRespondsToFunctionKeys = TRUE;
- } // TScroller::TScroller
-
- //----------------------------------------------------------------------------------------
- // TScroller::IScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScroller::IScroller(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const VPoint& itsMax,
- Boolean wantHorzSBar,
- Boolean wantVertSBar)
-
- {
- TDocument * itsSuperViewsDocument = NULL;
-
- if (itsSuperView)
- itsSuperViewsDocument = itsSuperView->fDocument;
-
- this->IView(itsSuperViewsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- FailInfo fi;
- Try(fi)
- {
- this->SetScrollParameters(VPoint(kStdScrollUnit, kStdScrollUnit), FALSE, FALSE);
-
- this->SetScrollLimits(itsMax, kDontRedraw);
-
- if (wantHorzSBar)
- this->CreateScrollBar(hSel);
- if (wantVertSBar)
- this->CreateScrollBar(vSel);
-
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- if (wantHorzSBar || wantVertSBar)
- this->AdjustScrollBars(kDontInvalidate);
- } // TScroller::IScroller
-
- //----------------------------------------------------------------------------------------
- // TScroller::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- TObject* TScroller::Clone() // override
- {
- MAVolatileInit(TScroller*, aClonedScroller, (TScroller *)(Inherited::Clone()));
-
- aClonedScroller->fScrollBars[vSel] = NULL; // so failure handler works
- aClonedScroller->fScrollBars[hSel] = NULL;
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- if (fScrollBars[vhs])
- {
- FailInfo fi;
- Try(fi)
- {
- aClonedScroller->fScrollBars[vhs] = (TScrollerScrollBar*)(fScrollBars[vhs]->Clone());
- aClonedScroller->fScrollBars[vhs]->AttachScroller(aClonedScroller);
- fi.Success();
- }
- else
- {
- aClonedScroller = (TScroller*) FreeIfObject( aClonedScroller );
- fi.ReSignal();
- }
- }
- }
- return aClonedScroller;
- } // TScroller::Clone
-
- //----------------------------------------------------------------------------------------
- // TScroller::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TScroller::~TScroller()
- {
- fScrollBars[hSel] = (TScrollerScrollBar *)(FreeIfObject(fScrollBars[hSel]));
- fScrollBars[vSel] = (TScrollerScrollBar *)(FreeIfObject(fScrollBars[vSel]));
- } // TScroller::Free
-
- //----------------------------------------------------------------------------------------
- // TScroller::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TScroller::GetStandardSignature() // override
- {
- return kStdScroller;
- } // TScroller::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TScroller::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TScroller::ReadFields(TStream* aStream) // override
- {
- Inherited::ReadFields(aStream);
-
- VPoint scrollLimit;
- VPoint scrollUnits;
- Boolean horzConstraint;
- Boolean vertConstraint;
-
- FailInfo fi;
- Try(fi)
- {
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- fScrollBarIdentifiers[vhs] = aStream->ReadIDType();
-
- aStream->ReadVPoint(scrollLimit);
- aStream->ReadVPoint(scrollUnits);
- vertConstraint = aStream->ReadBoolean();
- horzConstraint = aStream->ReadBoolean();
- VRect sBarOffsets;
- aStream->ReadVRect(sBarOffsets);
- fSBarOffsets = sBarOffsets;
- fRespondsToFunctionKeys = aStream->ReadBoolean();
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- this->SetScrollLimits(scrollLimit, kDontRedraw);
-
- this->SetScrollParameters(scrollUnits, horzConstraint, vertConstraint);
- } // TScroller::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TScroller::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TScroller::WriteFields(TStream* aStream) // override
- {
- VHSelect vhs;
-
- Inherited::WriteFields(aStream);
-
- for (vhs = vSel; vhs <= hSel; ++vhs)
- aStream->WriteIDType(fScrollBarIdentifiers[vhs]);
-
- aStream->WriteVPoint(fScrollLimit); // write scroll limits
- aStream->WriteVPoint(fScrollUnit); // write scroll units
-
- for (vhs = vSel; vhs <= hSel; ++vhs)
- aStream->WriteBoolean(fConstrain[vhs]);
-
- aStream->WriteVRect(fSBarOffsets); // write scrollbar offsets
- aStream->WriteBoolean(fRespondsToFunctionKeys);
- } // TScroller::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TScroller::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScroller::DoPostCreate(TDocument* itsDocument)
- {
- Inherited::DoPostCreate(itsDocument);
-
- Boolean needsAdjustScrollBar = FALSE;
-
- if (fSuperView)
- {
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- if ((fScrollBarIdentifiers[vhs] != kNoIdentifier) && (fScrollBars[vhs] == NULL))
- {
- TScrollerScrollBar* aScrollBar = (TScrollerScrollBar*) fSuperView->FindSubView(fScrollBarIdentifiers[vhs]);
- if (aScrollBar)
- {
- aScrollBar->AttachScroller(this);
- needsAdjustScrollBar = TRUE;
- }
- #if qDebugMsg
- else
- {
- IDType itsID = fScrollBarIdentifiers[vhs];
- fprintf(stderr, "###In TScroller::DoPostCreate, can't find scrollbar: %.4s\n", (char *)&itsID);
- }
- #endif
- }
- }
-
- this->AdjustScrollLimits(kDontRedraw);
-
- if (needsAdjustScrollBar)
- this->AdjustScrollBars(kDontInvalidate);
- } // TScroller::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TScroller::AddedASubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScroller::AddedASubView(TView* theSubView)// override
- {
- Inherited::AddedASubView(theSubView);
-
- // if this scroller is the direct superview of the subview
- // accept ownership and recalculate scroll limits
- // (we don't want any other scrollers doing this too)
- if (theSubView->fSuperView == this)
- {
- theSubView->BeInScroller(this);
- this->AdjustScrollLimits(kDontRedraw);
- }
- } // TScroller::AddedASubView
-
- //----------------------------------------------------------------------------------------
- // TScroller::AdjustScrollBars:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::AdjustScrollLimits(Boolean drawScrollBars)
- {
- VRect aggregateExtents(gZeroVRect);
- CSubViewIterator iter(this);
-
- for (TView* aSubView = iter.FirstSubView(); iter.More(); aSubView = iter.NextSubView())
- if (aSubView->fShown)
- aggregateExtents = aggregateExtents | aSubView->GetFrame(); // union the new frame into the aggregate
-
- this->SetScrollLimits(aggregateExtents.GetSize(), drawScrollBars);
- }
-
- //----------------------------------------------------------------------------------------
- // TScroller::AdjustScrollBars:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::AdjustScrollBars(Boolean invalidate)
- {
- VHSelect ortho;
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- TScrollBar * aScrollBar = fScrollBars[vhs];
- if (aScrollBar)
- {
- ortho = gOrthogonal[vhs];
- VPoint loc = fLocation;
- VPoint size = fSize;
-
- loc[vhs] += fSBarOffsets[topLeft][vhs] - 1;
- loc[ortho] += size[ortho];
-
- size[vhs] = size[vhs] - fSBarOffsets[topLeft][vhs] + fSBarOffsets[botRight][vhs] + 2;
- #if 1
- // ••• Temporary
- size[ortho] = kSBarSize;
- #else
- size[ortho] = aScrollBar->fSize[ortho];
- #endif
-
- aScrollBar->SetFrame(VRect(loc, loc + size), invalidate);
- }
- }
- } // TScroller::AdjustScrollBars
-
- //----------------------------------------------------------------------------------------
- // TScroller::AutoScroll:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TScroller::AutoScroll(const VPoint& viewPt,
- VPoint& delta)
- {
- delta = gZeroVPt;
- VRect myExtent(this->GetExtent());
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- if (viewPt[vhs] < myExtent[topLeft][vhs])
- delta[vhs] = -ProportionalScroll(myExtent[topLeft][vhs] - viewPt[vhs], fScrollUnit[vhs], fTranslation[vhs]);
- else if (viewPt[vhs] > myExtent[botRight][vhs])
- delta[vhs] = ProportionalScroll(viewPt[vhs] - myExtent[botRight][vhs], fScrollUnit[vhs], fMaxTranslation[vhs] - fTranslation[vhs]);
- } // TScroller::AutoScroll
-
- //----------------------------------------------------------------------------------------
- // TScroller::CreateScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScroller::CreateScrollBar(VHSelect itsDirection)
- {
- TScrollerScrollBar * aScrollerScrollBar = new TScrollerScrollBar;
- aScrollerScrollBar->IScrollerScrollBar(fSuperView, gZeroVPt, gZeroVPt, sizeVariable, sizeVariable, itsDirection, fMaxTranslation[itsDirection], this);
- } // TScroller::CreateScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScroller::DoKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
- void TScroller::DoKeyEvent(TToolboxEvent* event)// override
- {
- Boolean wasHandled = FALSE;
-
- if (this->IsEnabled() && fRespondsToFunctionKeys)
- {
- wasHandled = TRUE;
- if (event->fText == chPageUp)
- {
- if (fScrollBars[vSel])
- fScrollBars[vSel]->DeltaValue(VCoordinate(this->ScrollStep(vSel, kControlPageUpPart)));
- }
- else if (event->fText == chPageDown)
- {
- if (fScrollBars[vSel])
- fScrollBars[vSel]->DeltaValue(VCoordinate(this->ScrollStep(vSel, kControlPageDownPart)));
- }
- else if (event->fText == chHome)
- this->SetLocalOrigin(gZeroVPt, kRedraw);
- else if (event->fText == chEnd)
- this->SetLocalOrigin(VPoint(0, fMaxTranslation.v), kRedraw);
- else
- wasHandled = FALSE;
- }
-
- if (wasHandled)
- this->Update();
- else
- Inherited::DoKeyEvent(event);
- } // TScroller::DoKeyEvent
-
- //----------------------------------------------------------------------------------------
- // TScroller::DoScroll:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScroller::DoScroll(const VPoint& delta,
- Boolean redraw)
- {
- VPoint localDelta(delta);
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- if (localDelta[vhs] < 0)
- localDelta[vhs] = Max(localDelta[vhs], -fTranslation[vhs]);
- else if (localDelta[vhs] > 0)
- localDelta[vhs] = Min(localDelta[vhs], (fMaxTranslation[vhs] - fTranslation[vhs]));
- fTranslation[vhs] += localDelta[vhs];
- }
-
- if (localDelta != gZeroVPt)
- {
- this->InvalidateFocus();
- this->InvalidateCoordinates();
-
- if (redraw)
- this->ScrollDraw(localDelta, kDontInvalidate); // Don't invalidate means "draw don't invalidate"
- }
- } // TScroller::DoScroll
-
- //----------------------------------------------------------------------------------------
- // TScroller::ForceRedraw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerRes
-
- void TScroller::ForceRedraw() // override
- {
- Inherited::ForceRedraw();
-
- if (fScrollBars[hSel])
- fScrollBars[hSel]->ForceRedraw();
- if (fScrollBars[vSel])
- fScrollBars[vSel]->ForceRedraw();
- } // TScroller::ForceRedraw
-
- //----------------------------------------------------------------------------------------
- // TScroller::GetScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerRes
-
- TScroller* TScroller::GetScroller(Boolean)
- {
- return this;
- } // TScroller::GetScroller
-
- //----------------------------------------------------------------------------------------
- // TScroller::HaveScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerRes
-
- void TScroller::HaveScrollBar(TScrollerScrollBar* theScrollBar,
- VHSelect direction)
- {
- #if qDebug
- if ((theScrollBar) && (theScrollBar->fDirection != direction))
- ProgramBreak("Scroll bar is wrong direction.");
- #endif
-
- fScrollBars[direction] = theScrollBar;
- } // TScroller::HaveScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScroller::RemovedASubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::RemovedASubView(TView* theSubView)// override
- {
- Inherited::RemovedASubView(theSubView);
-
- if (theSubView->fSuperView == this)
- {
- theSubView->BeInScroller(NULL);
- this->AdjustScrollLimits(kDontRedraw);
- }
- } // TScroller::RemovedASubView
-
- //----------------------------------------------------------------------------------------
- // TScroller::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::SetFrame(const VRect& newFrame, Boolean invalidate)// override
-
- {
- VPoint oldSize(fSize);
- Inherited::SetFrame(newFrame, invalidate);
-
- this->AdjustScrollBars(invalidate);
-
- if (oldSize != fSize)
- this->SetScrollLimits(fScrollLimit, kDontRedraw); // Readjust sbar maximums and fMaxTranslation
- } // TScroller::SetFrame
-
- //----------------------------------------------------------------------------------------
- // TScroller::RevealRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScroller::RevealRect(const VRect& rectToReveal,
- const VPoint& minToSee,
- Boolean redraw)// override
- {
- VRect myExtent(this->GetExtent());
-
- VPoint delta;
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- VCoordinate minAmt = Min(myExtent.GetLength(vhs), minToSee[vhs]);
- VCoordinate coord = rectToReveal[topLeft][vhs] + minAmt - myExtent[botRight][vhs];
- if (coord <= 0)
- coord = Min(0, rectToReveal[botRight][vhs] - minAmt - myExtent[topLeft][vhs]);
- delta[vhs] = coord;
- }
-
- this->ScrollBy(delta, redraw);
- Inherited::RevealRect(rectToReveal, minToSee, redraw);
- } // TScroller::RevealRect
-
- //----------------------------------------------------------------------------------------
- // TScroller::ScrollBy:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScroller::ScrollBy(const VPoint& delta,
- Boolean redraw)
- {
- if (delta != gZeroVPt)
- {
- if (fScrollBars[vSel])
- fScrollBars[vSel]->DeltaValue(delta.v);
-
- if (fScrollBars[hSel])
- fScrollBars[hSel]->DeltaValue(delta.h);
-
- this->DoScroll(delta, redraw);
- }
- } // TScroller::ScrollBy
-
- //----------------------------------------------------------------------------------------
- // TScroller::ScrollDraw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScroller::ScrollDraw(const VPoint& delta,
- Boolean invalidate)
- {
- if (!this->GetVisibleExtent().Empty() && this->IsShown() && this->Focus())
- {
- CRect visRect((*GetClipRegion(qd.thePort))->rgnBBox); // just test the clip, it's faster
-
- #if qDebug
- if (gIntenseDebugging)
- WriteFocus();
- #endif
- if (!visRect.Empty())
- {
- const VRect visVRect(visRect);
- if (((visVRect - delta) & visVRect).Empty()) // too far to scrollrect
- this->InvalidateRect(visRect);
- else
- {
- CTemporaryRegion tempRgn;
-
- ScrollRect(visRect, (short)(-delta.h), (short)(-delta.v), tempRgn);
- this->InvalidateRegion(tempRgn);
- }
-
- if (!invalidate)
- this->Update();
- }
- }
- } // TScroller::ScrollDraw
-
- //----------------------------------------------------------------------------------------
- // TScroller::ScrollRelative:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- VCoordinate TScroller::ScrollRelative(VHSelect vhs,
- VCoordinate sBarValue)
- {
- VPoint pixelDelta(0, 0);
- VCoordinate newValue;
-
- if ((fConstrain[vhs] && (sBarValue != fMaxTranslation[vhs])))
- newValue = (sBarValue + fScrollUnit[vhs] / 2) / fScrollUnit[vhs] * fScrollUnit[vhs];
- else
- newValue = sBarValue;
-
- pixelDelta[vhs] = newValue - fTranslation[vhs];
- this->DoScroll(pixelDelta, kRedraw);
- return (newValue - sBarValue);
- } // TScroller::ScrollRelative
-
- //----------------------------------------------------------------------------------------
- // TScroller::ScrollStep:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- VCoordinate TScroller::ScrollStep(VHSelect vhs,
- short partCode)
- {
- VCoordinate scrollUnit = fScrollUnit[vhs];
- VCoordinate delta;
-
- switch (partCode)
- {
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- delta = scrollUnit;
- break;
-
- case kControlPageUpPart:
- case kControlPageDownPart:
- delta = fSize[vhs] - scrollUnit;
- break;
-
- #if qDebug
- default:
- {
- CStr255 theString;
- ConcatNumber("TScroller::ScrollStep: bad part code =", partCode, theString);
- ProgramBreak(theString);
- }
- break;
- #endif
-
- }
-
- if ((partCode == kControlUpButtonPart) || (partCode == kControlPageUpPart))
- delta = -delta;
-
- // Constrain if necessary
- if (fConstrain[vhs] && (scrollUnit != 0))
- {
- VCoordinate adjustment = (Max(0, fTranslation[vhs] + delta)) % scrollUnit;
- if (adjustment != 0)
- if (delta > 0)
- delta -= adjustment;
- else
- delta += (scrollUnit - adjustment);
- }
-
- VPoint deltaPt(0, 0);
- deltaPt[vhs] = delta;
-
- this->DoScroll(deltaPt, kRedraw);
- return delta;
- } // TScroller::ScrollStep
-
- //----------------------------------------------------------------------------------------
- // TScroller::SetLocalOrigin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScroller::SetLocalOrigin(const VPoint& newOrigin,
- Boolean redraw)
- {
- ScrollBy(newOrigin - fTranslation, redraw);
- } // TScroller::SetLocalOrigin
-
- //----------------------------------------------------------------------------------------
- // TScroller::SetScrollLimits:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::SetScrollLimits(const VPoint& scrollLimit,
- Boolean drawScrollBars)
- {
- VPoint newTranslation(fTranslation);
-
- fScrollLimit = scrollLimit;
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- VCoordinate maxCoord = Max(0, scrollLimit[vhs] - fSize[vhs]);
-
- fMaxTranslation[vhs] = maxCoord;
- if (fScrollBars[vhs])
- fScrollBars[vhs]->SetLongMax(maxCoord, drawScrollBars);
-
- if (maxCoord < fTranslation[vhs])
- newTranslation[vhs] = maxCoord;
- }
-
- // This is very similar to ScrollBy except that the scrollbars
- // have to react in the opposite direction as the scrolling.
- VPoint delta = newTranslation - fTranslation;
- if (delta != gZeroVPt)
- {
- if (fScrollBars[vSel])
- fScrollBars[vSel]->DeltaValue(-delta.v);
-
- if (fScrollBars[hSel])
- fScrollBars[hSel]->DeltaValue(-delta.h);
-
- this->DoScroll(delta, kRedraw);
- }
- } // TScroller::SetScrollLimits
-
- //----------------------------------------------------------------------------------------
- // TScroller::SetScrollParameters:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::SetScrollParameters(const VPoint& units,
- Boolean horzConstraint,
- Boolean vertConstraint)
- {
- fScrollUnit = units;
- fConstrain[hSel] = horzConstraint;
- fConstrain[vSel] = vertConstraint;
- } // TScroller::SetScrollParameters
-
- //----------------------------------------------------------------------------------------
- // TScroller::SubViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScrollerNonRes
-
- void TScroller::SubViewChangedFrame(TView* ,
- const VRect&,
- const VRect&,
- Boolean invalidate)// override
- {
- this->AdjustScrollLimits(invalidate);
- } // TScroller::SubViewChangedFrame
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TScroller::GetDragScrollDelta:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- VPoint TScroller::GetDragScrollDelta(const VPoint& mouseInWindow)
- {
- static const short kDragScrollRange = 16;
-
- VPoint scrollDelta(gZeroPt);
-
- TView* aScroller = this;
- VRect scrollerExtent(aScroller->GetVisibleExtent());
- while(aScroller) // convert to window coords
- {
- if (aScroller->fSuperView)
- aScroller->LocalToSuperVRect(scrollerExtent);
- aScroller = aScroller->fSuperView;
- }
-
- VHSelect vhSelect;
- for (vhSelect = vSel; vhSelect <= hSel; vhSelect++)
- {
- if (fScrollBars[vhSelect])
- {
- TView* aScrollBar = fScrollBars[vhSelect];
- VRect scrollBarExtent(aScrollBar->GetVisibleExtent());
- while(aScrollBar) // convert to window coords
- {
- if(aScrollBar->fSuperView)
- aScrollBar->LocalToSuperVRect(scrollBarExtent);
- aScrollBar = aScrollBar->fSuperView;
- }
-
- VCoordinate firstDiff = scrollerExtent[topLeft][vhSelect] - scrollBarExtent[botRight][vhSelect];
- VCoordinate secondDiff = scrollBarExtent[topLeft][vhSelect] - scrollerExtent[botRight][vhSelect];
-
- // if scroll bar is adjacent to the scroller, union it into the scroller extent
- if (firstDiff <= 1 || secondDiff <= 1)
- scrollerExtent = (scrollerExtent | scrollBarExtent);
- }
- }
-
- if (scrollerExtent.Contains(mouseInWindow))
- {
- VPoint extentDelta(kDragScrollRange, kDragScrollRange);
-
- scrollerExtent.Inset(extentDelta); // inset the extent
-
- if (!scrollerExtent.Contains(mouseInWindow))
- {
- for (vhSelect = vSel; vhSelect <= hSel; vhSelect++)
- {
- // adjust scroll delta. test scrolling in all 4 directions
- // if the scroller scrolls up AND down, it'll resolve to a
- // no vertical scroll. this handles overlapping opposing scroll areas
- if ((mouseInWindow[vhSelect] < scrollerExtent[topLeft][vhSelect]) &&
- (fTranslation[vhSelect] > 0))
- scrollDelta[vhSelect] = -fScrollUnit[vhSelect];
-
- if ((mouseInWindow[vhSelect] > scrollerExtent[botRight][vhSelect]) &&
- (fMaxTranslation[vhSelect] - fTranslation[vhSelect]) > 0)
- scrollDelta[vhSelect] = fScrollUnit[vhSelect];
- }
- }
- }
- return scrollDelta;
- }
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // End of UScroller.cp
-
- #pragma segment Inline
-